package Users;

import java.util.ArrayList;

/*
 * UserAccount has all the information for one user.
 */
public class UserAccount {
	private int accountID;
	private String userName;
	private String password;
	private ArrayList<TaskData> taskList;
	private int taskNumberCounter;
	
	public UserAccount() {
		accountID = -1;
		userName = "";
		password = "";
		taskList = new ArrayList<TaskData>();
		taskNumberCounter = 1;
	}
	
	public UserAccount(int id) {
		accountID = id;
		taskList = new ArrayList<TaskData>();
		taskNumberCounter = 1;
	}
	
	public UserAccount(int id, String name, String pwd) {
		accountID = id;
		userName = name;
		password = pwd;
		taskList = new ArrayList<TaskData>();
		taskNumberCounter = 1;
	}
	
	public final int getAccountID() {
		return accountID;
	}
	
	public final String getUserName() {
		return userName;
	}
	
	public final String getPassword() {
		return password;
	}
	
	public final ArrayList<TaskData> getTaskList() {
		return taskList;
	}
	
	public void setAccountID(int id) {
		accountID = id;
	}
	
	public void setUserName(String input) {
		userName = input;
	}
	
	public void setPassword(String input) {
		password = input;
	}
	
	public void addTask(TaskData newTask) {
		newTask.setTaskId(taskNumberCounter++);
		taskList.add(newTask);
	}
	
	public boolean removeTask(int taskID) {
		for(int x = 0; x < taskList.size(); x++) {
			if (taskList.get(x).getTaskId() == taskID) {
				taskList.remove(x);
				return true;
			}
		}
		return false;
	}
	
	public boolean editTask(TaskData task) {
		for(int x = 0; x < taskList.size(); x++) {
			if (taskList.get(x).getTaskId() == task.getTaskId()) {
				taskList.set(x, task);
				return true;
			}
		}
		return false;
	}
	
	public String getTasksToString() {
		String tasks = "";
		if(!taskList.isEmpty()) {
			for(int x = (taskList.size() -1); x >= 0; x--) {
				tasks += taskList.get(x).toString();
			}
		}
			
		return tasks;
	}
	
	// Search through the array to find the array location of the matching taskID.
	public int findTaskIDLocation(int taskID) {
		for(int x = 0; x < taskList.size(); x++) {
			if (taskList.get(x).getTaskId() == taskID)
				return x;
		}
		
		return -1;
	}
	
	public boolean isPasswordCorrect(String input) {
		return password.contentEquals(input);
	}
}
